package com.ase.leetcode.threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author gyhstart
 * @create 2021/4/13 - 9:28
 **/
public class ThreadPool {
    public static void main(String[] args) {
        pool(10);
    }

    public static void pool(int n) {
        //创建线程池
        ExecutorService threadPool = Executors.newFixedThreadPool(n);
        while (true) {
            threadPool.execute(() -> {
                System.out.println(Thread.currentThread().getId() + " - " + Thread.currentThread().getName() + " is running");
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            });
        }
    }
}
